﻿using per.esmool.utils.DB;
using per.esmool.utils.DB.MySQL;
using System;

namespace FlowSimulate.MySQL {

    public class Action() : IIDData<Action> {

        public Action Copy() {
            var action = new Action() {
                Id         = this.Id,
                ObjectType = this.ObjectType,
                ObjectID   = this.ObjectID,
                Product    = this.Product,
                Project    = this.Project,
                Actor      = this.Actor,
                Content    = this.Content,
                Date       = this.Date,
                Comment    = this.Comment,
                Extra      = this.Extra,
                Read       = this.Read,
            };
            return action;
        }

        [DbField]                  public int      Id         { get; set; }
        [DbField]                  public string   ObjectType { get; set; }
        [DbField]                  public int      ObjectID   { get; set; }
        [DbField]                  public string   Product    { get; set; }
        [DbField]                  public int      Project    { get; set; }
        [DbField]                  public string   Actor      { get; set; }
        [DbField(Name = "action")] public string   Content    { get; set; }
        [DbField]                  public DateTime Date       { get; set; }
        [DbField]                  public string   Comment    { get; set; }
        [DbField]                  public string   Extra      { get; set; }
        [DbField]                  public bool     Read       { get; set; }
    }

    public class ActionDao() : MySQLModel<Action> {

        public override string TableName => "zt_action";

        public int InsertComment(int taskId, string assetId, DateTime commentTime, string comment) {
            var action = new Action() {
                ObjectType = "task"                  , // <固定值>
                ObjectID   = taskId                  , // <task ID>
                Actor      = assetId                 , // <创建者账号>
                Content    = "Commented"             , // <opened/started/finished/closed/commented>
                Date       = commentTime             , // <创建时间>
                Comment    = comment                 , // <备注内容>
                Extra      = ""                      , // <固定值>
                Product    = ",,"                    , // <固定值>
                Project    = 1                       , // <固定值>
                Read       = false                   , // <固定值>
            };
            return this.Insert(action);
        }

        public int InsertAction(int taskId, string assetId, string actionType, DateTime actionTime, string comment) {
            var action = new Action() {
                ObjectType = "task"                  , // <固定值>
                ObjectID   = taskId                  , // <task ID>
                Actor      = assetId                 , // <创建者账号>
                Content    = actionType              , // <opened/started/finished/closed/commented>
                Date       = actionTime              , // <创建时间>
                Comment    = comment                 , // <备注内容>
                Extra      = ""                      , // <固定值>
                Product    = ",,"                    , // <固定值>
                Project    = 1                       , // <固定值>
                Read       = false                   , // <固定值>
            };
            return this.Insert(action);
        }

    }
}
